package com.ruoyi.web.controller.wechat;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.controller.wechat.request.ImageFusionRequest;
import com.ruoyi.web.controller.wechat.response.ImageFusionResponse;
import com.ruoyi.web.service.ImageFusionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 图片融合控制器
 *
 * @author chenchuan2
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/wechat-api/ygImage")
@Slf4j
public class ImageFusionController extends AuthController {

    @Autowired
    private ImageFusionService imageFusionService;

    @ApiOperation("图片融合")
    @PostMapping("/fusion")
    public R<ImageFusionResponse> fusion(@Validated @RequestBody ImageFusionRequest request) {
        String openId = getOpenId();
        int base64Count = (request.getBase64Images() != null) ? request.getBase64Images().size() : 0;
        int urlCount = (request.getUrlImages() != null) ? request.getUrlImages().size() : 0;
        log.info("用户 {} 请求图片融合，base64图片数量：{}，URL图片数量：{}", openId, base64Count, urlCount);

        try {
            ImageFusionResponse response = imageFusionService.fusionImages(request, openId);
            return R.ok(response);
        } catch (Exception e) {
            log.error("图片融合失败", e);
            return R.fail("图片融合失败：" + e.getMessage());
        }
    }
}
